﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;

namespace HML.SkinTool
{
    public class TreeListViewPropertyGridItem
    {
        #region

        /// <summary>
        /// 属性名称
        /// </summary>
        public string PropertyName { get; set; }
        /// <summary>
        /// 属性值
        /// </summary>
        public object PropertyValue { get; set; }
        /// <summary>
        /// 属性显示值
        /// </summary>
        public string PropertyDisplayValue { get; set; }
        /// <summary>
        /// 属性描述
        /// </summary>
        public string PropertyDescription { get; set; }
        /// <summary>
        /// 属性的元数据信息
        /// </summary>
        public PropertyInfo PropertyInfo { get; set; }
        /// <summary>
        /// 属性排列序号
        /// </summary>
        public float PropertyOrder { get; set; }
        /// <summary>
        /// 主题属性的XPath路径
        /// </summary>
        public string XPath { get; set; }
        /// <summary>
        /// 子属性集合
        /// </summary>
        public List<TreeListViewPropertyGridItem> Children { get; set; }
        /// <summary>
        /// 是否为环境属性
        /// </summary>
        public bool EnvironmentProperty { get; set; }
        /// <summary>
        /// 是否可以编辑
        /// </summary>
        public bool IsAllowEdit { get; set; }
        /// <summary>
        /// 属性编辑器类型
        /// </summary>
        public EditorAttribute EditorAttribute { get; set; }
        /// <summary>
        /// 属性拥有者
        /// </summary>
        public object PropertyOwnerObject { get; set; }

        #endregion

        public TreeListViewPropertyGridItem(string propertyName, object propertyValue, string propertyDisplayValue, string propertyDescription, PropertyInfo propertyInfo, float propertyOrder, string xPath, bool environmentProperty, bool isAllowEdit, EditorAttribute editorAttribute, object propertyOwnerObject)
        {
            this.PropertyOwnerObject = propertyOwnerObject;
            this.PropertyName = propertyName;
            this.PropertyValue = propertyValue;
            this.PropertyDisplayValue = propertyDisplayValue;
            this.PropertyDescription = propertyDescription;
            this.PropertyInfo = propertyInfo;
            this.PropertyOrder = propertyOrder;
            this.XPath = xPath;
            this.Children = new List<TreeListViewPropertyGridItem>();
            this.EnvironmentProperty = environmentProperty;
            this.IsAllowEdit = isAllowEdit;
            this.EditorAttribute = editorAttribute;
        }

        public class Comparer : IComparer<TreeListViewPropertyGridItem>
        {
            public int Compare(TreeListViewPropertyGridItem x, TreeListViewPropertyGridItem y)
            {
                if (x.PropertyOrder > y.PropertyOrder)
                    return 1;
                else if (x.PropertyOrder < y.PropertyOrder)
                    return -1;
                else
                    return 0;
            }
        }

    }

}
